/*********************************************************
 * copyright xinbohit.com 版权所有 
 * 开发人员：IvanYu
 * 创建时间：2014/6/7 17:20:01
 * 描述说明：
 * 
 * 更改历史：
 * 
 * *******************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KouSuan.Models;
using KouSuan.Generaters;

namespace KouSuan.Classes
{
    static class GenerateQuestionsEngine
    {
        static Dictionary<ExaminationType, IGenerater> Mapping;

        static GenerateQuestionsEngine()
        {
            Mapping = new Dictionary<ExaminationType, IGenerater>();
            Mapping.Add(ExaminationType.FiveAddition, new FiveAddGenerater());
            Mapping.Add(ExaminationType.FiveSubstraction, new FiveSubtractGenerater());
            Mapping.Add(ExaminationType.TenAddition, new TenAddGenerater());
            Mapping.Add(ExaminationType.TenSubstraction, new TenSubtractGenerater());
            Mapping.Add(ExaminationType.TwentyAddition, new TwentyAddGenerater());
            Mapping.Add(ExaminationType.TwentySubstraction, new TwentySubtractGenerater());
            Mapping.Add(ExaminationType.TwentyCarrySaveAddition, new TwentyCarrySaveAdditionGenerater());
            Mapping.Add(ExaminationType.TwentyAbdicationSubtraction, new TwentyAbdicationSubtractionGenerater());
            Mapping.Add(ExaminationType.HundredAddition, new HundredAddGenerater());
            Mapping.Add(ExaminationType.HundredSubstraction, new HundredSubtractGenerater());
            Mapping.Add(ExaminationType.HundredCarrySaveAddition, new HundredCarrySaveAdditionGenerater());
            Mapping.Add(ExaminationType.HundredAbdicationSubtraction, new HundredAbdicationSubtractionGenerater());
        }

        static Random r = new Random();

        public static IList<ExpressionModel> Generate(int count, ExaminationType type)
        {
            List<ExpressionModel> result = new List<ExpressionModel>();
            int ty;
            IGenerater g;

            switch (type)
            {
                case ExaminationType.FiveAddition:
                case ExaminationType.FiveSubstraction:
                case ExaminationType.TenAddition:
                case ExaminationType.TenSubstraction:
                case ExaminationType.TwentyAddition:
                case ExaminationType.TwentySubstraction:
                case ExaminationType.TwentyCarrySaveAddition:
                case ExaminationType.TwentyAbdicationSubtraction:
                case ExaminationType.HundredAddition:
                case ExaminationType.HundredSubstraction:
                case ExaminationType.HundredCarrySaveAddition:
                case ExaminationType.HundredAbdicationSubtraction:
                    g = Mapping[type];
                    for (int i = 0; i < count; i++)
                    {
                        result.Add(g.Generate());
                    }
                    break;
                case ExaminationType.FiveAll:
                    for (int i = 0; i < count; i++)
                    {
                        ty = r.Next(2);
                        if (ty == 0)
                        {
                            result.Add(Mapping[ExaminationType.FiveAddition].Generate());
                        }
                        else
                        {
                            result.Add(Mapping[ExaminationType.FiveSubstraction].Generate());
                        }
                    }
                    break;
                case ExaminationType.TenAll:
                    for (int i = 0; i < count; i++)
                    {
                        ty = r.Next(2);
                        if (ty == 0)
                        {
                            result.Add(Mapping[ExaminationType.TenAddition].Generate());
                        }
                        else
                        {
                            result.Add(Mapping[ExaminationType.TenSubstraction].Generate());
                        }
                    }
                    break;
                case ExaminationType.TwentyAll:
                    for (int i = 0; i < count; i++)
                    {
                        ty = r.Next(2);
                        if (ty == 0)
                        {
                            result.Add(Mapping[ExaminationType.TwentyAddition].Generate());
                        }
                        else
                        {
                            result.Add(Mapping[ExaminationType.TwentySubstraction].Generate());
                        }
                    }
                    break;
                case ExaminationType.HundredAll:
                    for (int i = 0; i < count; i++)
                    {
                        ty = r.Next(2);
                        if (ty == 0)
                        {
                            result.Add(Mapping[ExaminationType.HundredAddition].Generate());
                        }
                        else
                        {
                            result.Add(Mapping[ExaminationType.HundredSubstraction].Generate());
                        }
                    }
                    break;
                default:
                    break;
            }

            return result;
        }
    }
}
